package com.depin.pdaapp.utils;

import android.util.Log;

/**
 * Created by lzn.
 * Date：2020/4/8 9:16
 * Desc：日志工具类
 **/
public class LogUtils {
    private static int currentLev = 4;
    private static int DEBUG_LEV = 4;
    private static int INFO_LEV = 3;
    private static int WARN_LEV = 2;
    private static int ERROR_LEV = 1;

    /**
     * 截断输出日志
     *
     * @param msg
     */
    public static void longd(String tag, String msg) {
        if (tag == null || tag.length() == 0
                || msg == null || msg.length() == 0)
            return;

        int segmentSize = 3 * 1024;
        long length = msg.length();
        if (length <= segmentSize) {// 长度小于等于限制直接打印
            Log.d(tag, msg);
        } else {
            while (msg.length() > segmentSize) {// 循环分段打印日志
                String logContent = msg.substring(0, segmentSize);
                msg = msg.replace(logContent, "");
                Log.d(tag, logContent);
            }
            Log.d(tag, msg);// 打印剩余日志
        }
    }


    public static void d(Class clazz, String log) {
        if (currentLev >= DEBUG_LEV) {
            Log.d(clazz.getSimpleName() + "==========>", log);
        }
    }


    public static void i(Class clazz, String log) {
        if (currentLev >= INFO_LEV) {
            Log.i(clazz.getSimpleName() + "==========>", log);
        }
    }

    public static void w(Class clazz, String log) {
        if (currentLev >= WARN_LEV) {
            Log.w(clazz.getSimpleName() + "==========>", log);
        }
    }

    public static void e(Class clazz, String log) {
        if (currentLev >= ERROR_LEV) {
            Log.e(clazz.getSimpleName() + "==========>", log);
        }
    }
}
